package com.lagou.servlet;

import com.lagou.bean.Class;
import com.lagou.service.ClassService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "addClassServlet", value = "/addClassServlet")
public class addClassServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    this.doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //1.设置编码格式
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        //2.根据请求获取参数
        String cname = request.getParameter("cname");
        String grade = request.getParameter("grade");
        String teacher = request.getParameter("teacher");
        String slogan = request.getParameter("slogan");
        //3.创建Class对象传给ClassDao进行添加班级
        Class aClass = new Class(cname, grade, teacher, slogan, 0);
        ClassService classService = new ClassService();
        int i = classService.addClass(aClass);
        //添加完成跳转页面
        response.sendRedirect("ClassServlet");


    }
}
